<script type="text/javascript">
	var winW = $(window).width() - 180;
	var winH = $(window).height() - 180;
	 function detail(param1){
	 	jQuery.ajax({
	 	  url: '<?php echo base_url() ?>admin/detail',
	 	  type: 'POST',
	 	  data: {idsurat: param1},
	 	  complete: function(xhr, textStatus) {
	 	    //called when complete
	 	  },
	 	  success: function(data, textStatus, xhr) {
	 	    //called when successful
	 	    $("#detail_data").html(data);
	 	    $('div#detail_data').dialog(
	 	    	{
				    // height: winH,
				    width: winW,
				    modal: true
				});
	 	  },
	 	  error: function(xhr, textStatus, errorThrown) {
	 	    //called when there is an error
	 	  }
	 	});



	 }
</script>

<div class="clearfix">
<div class="row">
  <div class="col-lg-12">

	<div class="navbar navbar-inverse">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand" href="#">Surat Masuk</a>
			</div>
		<div class="navbar-collapse collapse navbar-inverse-collapse" style="margin-right: -20px">
			<ul class="nav navbar-nav">
				<?php
					if($this->session->userdata('admin_level') != "Staff"){
				?>
				<li><a href="<?php echo base_URL(); ?>admin/surat_masuk/add" class="btn-info"><i class="icon-plus-sign icon-white"> </i> Tambah Data</a></li>
				<?php
					}
				?>
			</ul>

			<ul class="nav navbar-nav navbar-right">
				<form class="navbar-form navbar-left" method="post" action="<?=base_URL()?>admin/surat_masuk/cari">
					<input type="text" class="form-control" name="q" style="width: 200px" placeholder="Kata kunci pencarian ..." required>
					<button type="submit" class="btn btn-danger"><i class="icon-search icon-white"> </i> Cari</button>
				</form>
			</ul>
		</div><!-- /.nav-collapse -->
		</div><!-- /.container -->
	</div><!-- /.navbar -->

  </div>
</div>

<?php echo $this->session->flashdata("k");?>

<!--
<div class="alert alert-dismissable alert-success">
  <button type="button" class="close" data-dismiss="alert">x</button>
  <strong>Well done!</strong> You successfully read <a href="http://bootswatch.com/amelia/#" class="alert-link">this important alert message</a>.
</div>

<div class="alert alert-dismissable alert-danger">
  <button type="button" class="close" data-dismiss="alert">x</button>
  <strong>Oh snap!</strong> <a href="http://bootswatch.com/amelia/#" class="alert-link">Change a few things up</a> and try submitting again.
</div>
-->

<table class="table table-bordered table-hover">
	<thead>
		<tr>
			<th width="4%">No. Agd/Kode</th>
			<th width="4%"></th>
			<th width="4%"></th>
			<th width="4%">Posisi</th>
			<th width="27%">Isi Ringkas, File</th>
			<th width="10%">Asal Surat</th>
			<th width="15%">Nomor, Tgl. Surat</th>
			<th width="28%">Aksi</th>
		</tr>
	</thead>

	<tbody>
		<?php
		if (empty($data)) {
			echo "<tr><td colspan='5'  style='text-align: center; font-weight: bold'>--Data tidak ditemukan--</td></tr>";
		} else {
			$no 	= ($this->uri->segment(4) + 1);
			foreach ($data as $b) {

				//$encode_id=$this->encryption->safe_b64encode($b->id_disposisi);
				//echo $encode_id;
				//echo $this->encryption->safe_b64decode($encode_id);
		?>
				<?php

				if($b->is_surat_masuk!='1'){
					$filter_id =$this->encryption->safe_b64encode($b->id . '-' . $b->id_disposisi . '-' . $b->id_status_disposisi);
				}else{
					$filter_id =$this->encryption->safe_b64encode($b->id . '-' . '0' . '-' . '0');
				}

				if (($this->session->userdata('admin_level') == "Admin") || ($this->session->userdata('admin_level') == "TU") ){

					if ($b->status=='selesai'){
						echo "<tr class='status_stop' onclick='detail(\"" . $filter_id . "\")'>";
					}else{
						if ( date('Y-m-d') > $b->tgl_surat ){
							echo "<tr class='status_urgent'  onclick='detail(\"" . $filter_id . "\")'>";
						}else{
							echo "<tr onclick='detail(\"" . $filter_id . "\")'>";
						}

					}

				}else{
					if (($this->session->userdata('kd_unit')==$b->kd_unit) && ($b->status=='selesai')){
						echo "<tr class='status_stop' onclick='detail(\"" . $filter_id . "\")'>";
					}else{
						echo "<tr onclick='detail(\"" . $filter_id . "\")'>";
					}
				}

				$arr_get_level=$this->mdl_reff_unit->get_by_kd_unit($b->kd_unit)->row();

				if (($b->is_surat_masuk=='1') || ($arr_get_level->level=='admin') || ($arr_get_level->level=='direktorat') || ($arr_get_level->level=='tu')){
					echo '<td colspan=3>' . $b->no_agenda.'/'. $b->kode . '</td>';
				}elseif(($arr_get_level->level=='kasubdit')){
					//echo '<tdcolspan=1></td><td>' . $b->no_agenda.'/'. $b->kode . '</td>';
					echo '<td></td><td colspan=2>' . $b->no_agenda.'/'. $b->kode . '</td>';
				}
				elseif(($arr_get_level->level=='sie')){
					//echo '<td></td><td></td><td>' . $b->no_agenda.'/'. $b->kode . '</td>';
					echo '<td></td><td></td><td>' . $b->no_agenda.'/'. $b->kode . '</td>';
				}
				?>
			<td><?php
				echo $b->is_surat_masuk .'-' .  $arr_get_level->nm_unit;
				?>
			</td>
			<td><?=$b->isi_ringkas."<br><b>File : </b><i><a href='".base_URL()."upload/surat_masuk/".$b->file."' target='_blank'>".$b->file."</a>"?></td>
			<td><?=$b->dari?></td>
			<td><?=$b->no_surat."<br><i>".tgl_jam_sql($b->tgl_surat)."</i>"?></td>

			<td class="ctr">
				<?php
				//if ($b->pengolah == $this->session->userdata('admin_id')) {
				?>
				<div class="btn-group">
					<?php
					if (($this->session->userdata('admin_level') == "Admin") || ($this->session->userdata('admin_level') == "TU") ){
					?>


					<?php
						if ($b->is_surat_masuk=='1'){
					?>
						<a href="<?=base_URL()?>admin/surat_masuk/edt/<?=$b->id?>" class="btn btn-success btn-sm" title="Edit Data"><i class="icon-edit icon-white"> </i> Edt</a>
						<a href="<?=base_URL()?>admin/surat_masuk/del/<?=$b->id?>" class="btn btn-warning btn-sm" title="Hapus Data" onclick="return confirm('Anda Yakin..?')"><i class="icon-trash icon-remove">  </i> Del</a>
						<!-- echo "<a href='" . base_url() . "admin/surat_disposisi/" . $b->id . "' class='btn btn-default btn-sm' title='Disposisi Surat'> <i class='icon-trash icon-list'> </i> Disp</a>"; -->
						<a href="<?=base_URL()?>admin/surat_disposisi/<?=$b->id?>" class="btn btn-default btn-sm"  title="Disposisi Surat"><i class="icon-trash icon-list"> </i> Disp</a>

						<a href="<?=base_URL()?>admin/surat_masuk/sts/<?=$this->encryption->safe_b64encode($b->id . '-' . '0')?>" class="btn btn-primary btn-sm" title="Selesai"><i class="icon-stop icon-white"> </i> Off</a>
					<?php
						}
					?>

					<?php

					?>
					<?php
					//}elseif (($this->session->userdata('admin_level') != "Admin") || ($this->session->userdata('admin_level') != "TU") && ($this->session->userdata('kd_unit')==$b->kd_unit)){
					}elseif (($this->session->userdata('kd_unit')==$b->kd_unit) && ($this->session->userdata('admin_level') != "Staff")){

					?>


						<a href="<?=base_URL()?>admin/surat_masuk/edt/<?=$b->id?>" class="btn btn-success btn-sm" title="Edit Data"><i class="icon-edit icon-white"> </i> Edt</a>
						<a href="<?=base_URL()?>admin/surat_masuk/del/<?=$b->id?>" class="btn btn-warning btn-sm" title="Hapus Data" onclick="return confirm('Anda Yakin..?')"><i class="icon-trash icon-remove">  </i> Del</a>
						<!-- echo "<a href='" . base_url() . "admin/surat_disposisi/" . $b->id . "' class='btn btn-default btn-sm' title='Disposisi Surat'> <i class='icon-trash icon-list'> </i> Disp</a>"; -->
						<a href="<?=base_URL()?>admin/surat_disposisi/<?=$b->id?>" class="btn btn-default btn-sm"  title="Disposisi Surat"><i class="icon-trash icon-list"> </i> Disp</a>
						<?php
							if ($b->is_surat_masuk=='1'){

						?>
							<a href="<?=base_URL()?>admin/surat_masuk/sts/<?=$this->encryption->safe_b64encode($b->id . '-' . '0')?>" class="btn btn-primary btn-sm" title="Selesai"><i class="icon-stop icon-white"> </i> Off</a>
						<?php
							}else{
						?>
							<a href="<?=base_URL()?>admin/surat_masuk/sts/<?=$this->encryption->safe_b64encode($b->id . '-' . $b->id_disposisi)?>" class="btn btn-primary btn-sm" title="Selesai"><i class="icon-stop icon-white"> </i> Off</a>
						<?php
							}
						?>
					<?php
					}elseif($this->session->userdata('admin_level') == "Staff"){
					?>
						<?php
						if ($b->is_surat_masuk=='1'){

						?>
						<a href="<?=base_URL()?>admin/surat_masuk/sts/<?=$this->encryption->safe_b64encode($b->id . '-' . '0')?>" class="btn btn-primary btn-sm" title="Selesai"><i class="icon-stop icon-white"> </i> Off</a>
						<?php
						}else{
						?>
						<a href="<?=base_URL()?>admin/surat_masuk/sts/<?=$this->encryption->safe_b64encode($b->id . '-' . $b->id_disposisi)?>" class="btn btn-primary btn-sm" title="Selesai"><i class="icon-stop icon-white"> </i> Off</a>
						<?php
						}
						?>
					<?php
					}
					?>
					<a href="<?=base_URL()?>admin/disposisi_cetak/<?=$b->id?>" class="btn btn-info btn-sm" target="_blank" title="Cetak Disposisi"><i class="icon-print icon-white"> </i> Ctk</a>
				</div>
				<?php
				//} else {
				?>
				<!--
				<div class="btn-group">
					<a href="<?=base_URL()?>admin/disposisi_cetak/<?=$b->id?>" class="btn btn-info btn-sm" target="_blank" title="Cetak Disposisi"><i class="icon-print icon-white"> </i> Ctk</a>
				</div>
-->
				<?php
				//}
				?>

			</td>
		</tr>
		<?php

			$no++;
			}
		}
		?>
	</tbody>
</table>
<center><ul class="pagination"><?php echo $pagi; ?></ul></center>
</div>


<div id="detail_data" title="Detail Surat Masuk"></div>